$(document).ready(function() {
	// 入库申请商品的数据绑定
	var inStockMaterialListVue = new Vue({
		el : '#inStockApplyMaterialDiv',
		data : {
			items : null
		},
		methods : {
			deleteIt : function(material, num) {
				openDeleteMaterialConfirm(material, num);
			}
		}
	});

	// 选择的商品
	var materialList = new Array();

	// 填写入库申请的按钮
	$("#chooseMaterialButton").on("click", function() {
		openChooseMaterialBox();
	});

	

	function openDeleteMaterialConfirm(material, num) {
		layer.confirm('确认删除:' + material.materialName, {
			btn : [ '确认', '取消' ]
		// 按钮
		}, function() {
			layer.msg('删除成功!');
			materialList.splice(num, 1);
			inStockMaterialListVue.items = materialList;
			$("#materialList").val(JSON.stringify(materialList));
		}, function() {

		});
	}

	function openChooseMaterialBox() {
		var chooseMaterialBox = layer.open({
			type : 2,
			offset : '10%',
			maxmin : true,
			title : '选择原料',
			area : [ '85%', '85%' ],
			btn : [ '确认', '取消' ] // 只是为了演示
			,
			yes : function() {
				var childBox = layer.getChildFrame('body', chooseMaterialBox);
				var m = childBox.find("#materialList").val();

				// 更新选择数据
				if (m != "") {
					m = eval('(' + m + ')');
					for ( var i in m) {
						materialList.push(m[i]);
					}
					inStockMaterialListVue.items = materialList;
					$("#materialList").val(JSON.stringify(materialList));
				}

				layer.close(chooseMaterialBox);

			},
			btn2 : function() {
				layer.close();
			},
			shadeClose : true, // 点击遮罩关闭
			content : JSP_PRE_URL + 'chooseMaterial'
		});

	}

});